local FileSystem = Tubes.FileSystem
FileSystem._RealFile = {}
local RealFile = FileSystem._RealFile
RealFile.__index = RealFile
setmetatable (RealFile, Tubes.FileSystem._File)

FileSystem.RealFile = Tubes.MakeConstructor (RealFile)

function RealFile:ctor (name)
	name = name:gsub ("\\", "/")
	self.RealPath = name
	
	local parts = string.Explode ("/", name)
	name = parts [#parts]
	FileSystem._File.ctor (self, name)
end

function RealFile:Delete (ply)
	if not self:PlayerHasPermission (ply, "Delete") then
		return
	end
	if self.RealPath:sub (1, 5):lower () == "data/" then
		file.Delete (self.RealPath:sub (6))
	end
	if not file.Exists (self.RealPath) then
		FileSystem._Base.Delete (self, ply)
	end
end

function RealFile:GetRealPath ()
	return self.RealPath
end

function RealFile:IsReal ()
	return true
end

function RealFile:Read (ply, callback)
	if not self:PlayerHasPermission (ply, "Read") then
		return
	end
	if not self.Contents then
		self.Contents = file.Read (self.RealPath, true) or "<read error>"
	end
	callback (self.Contents)
end